<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>访问器的优先级</title>
</head>
<body>
    <script>
        // 当对象中的属性名和方法名重复时，后者的优先级更高
        let hd = {
            name : "hdms",
            age : 18,
            set name(value){
                console.log(this.age + value);
            },
        };
        hd.name = "xiasnn";


        // 使用data可以用来避免属性名和方法名重复
        let hdms = {
            data : {name : "hdms",age :18},
            set name(value){
                this.data.name = value;
            },
            get name(){
                return this.data.name;
            }
        };
        hdms.name = "后盾人";
        // 还是可以修改data中的name
        hdms.data.name = "哈哈哈哈";
        console.log(hdms.name);


        // 在外部定义一个Symbol,用来保护data中的数据
        let DATA = Symbol();
        let hh = {
            [DATA] : {name : "hdms",age :18},
            set name(value){
                this[DATA].name = value;
            },
            get name(){
                return this[DATA].name;
            }
        };
        hh.name = "后盾人";
        // 不会修改到data中的name
        hdms.data.name = "哈哈哈哈";
        console.log(hh.name);
    </script>
</body>
</html>